import { ElSelect, ElOption } from 'element-plus';
import storeDict from '../../../store/sessionStorageDict/index'

const dictData = storeDict()
const select = (config, params) => {
    if(config.hasOwnProperty('dict')) {
        dictData.getDict(config.dict)
        return (
            <ElSelect {...config.props} v-model={params[config.props.prop]}  >
                {
                    handleFilterData(dictData.dictData[config.dict])?.map(cell => {
                        return (
                            <ElOption key={cell.value} label={cell.label} value={cell.value}></ElOption>
                        )
                    })
                }
            </ElSelect>
        )
    }else {
        return (
            <ElSelect {...config.props} v-model={params[config.props.prop]}  >
                {
                    config.options?.map(cell => {
                        return (
                            <ElOption key={cell.value} label={cell.label} value={cell.value}></ElOption>
                        )
                    })
                }
            </ElSelect>
        )
    }
}

// 处理 options 数据
function handleFilterData(dictData) {
    return dictData?.map(item => {
        return {
            label: item.dictLabel,
            value: item.dictValue
        }
    })
}

export default select
